package controllers.participant;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.EventService;
import domain.Challenge;
import domain.Event;

@Controller
@RequestMapping("/challenge/participant")
public class ChallengeParticipantController {

	@Autowired
	private EventService eventService;

	public ChallengeParticipantController() {
		super();
	}

	@RequestMapping(value="/list", method = RequestMethod.GET)
	public ModelAndView list(@RequestParam int eventId){
		ModelAndView result;
		Event evento = eventService.findOne(eventId);
		Collection<Challenge> challenges;
		challenges = evento.getChallenges();
		result = new ModelAndView("challenge/list");
		result.addObject("requestURI", "challenge/list.do");
		result.addObject("challenges", challenges);
		result.addObject("eventId", eventId);
		result.addObject("backURI", "/event/participant/edit.do?eventId="+eventId);
		return result;
	}
}
